<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="filter-item">
        <span class="span">执行器名称 </span>
        <el-input
          v-model="listQuery.appName"
          placeholder="请输入执行器名称"
          style="width: 200px;"
        />
      </div>
      <el-button
        v-waves
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
      >
        {{ $t('table.search') }}
      </el-button>
      <el-button v-waves plain v-permission="['dataextraction:DataExtractionGroup:add']" class="filter-item" style="margin-left: 10px" type="primary" icon="el-icon-edit" @click="handleCreate">
        {{ $t('table.add') }}
      </el-button>
      <el-button v-waves class="filter-item" icon="el-icon-refresh" @click="handleRest">{{ $t('table.rest') }}</el-button>
    </div>

    <el-table ref="table"    :key="tableKey" v-loading="listLoading" :data="list" max-height="590" element-loading-text="正在加载，请稍后" border fit highlight-current-row>
      <el-table-column type="index" align="center" width="100" label="序号" />
      <el-table-column label="执行器名称" align="center" min-width="150px">
        <template slot-scope="{ row }">
          <span>{{ row.appName }}</span>
        </template>
      </el-table-column>

      <el-table-column label="执行器类" align="center" min-width="150px">
        <template slot-scope="{ row }">
          <span>{{ row.executeClass }}</span>
        </template>
      </el-table-column>

      <el-table-column label="执行器方法" align="center" min-width="150px">
        <template slot-scope="{ row }">
          <span>{{ row.executeMethod }}</span>
        </template>
      </el-table-column>

      <el-table-column label="创建时间" align="center" min-width="150px">
        <template slot-scope="{ row }">
          <span>{{ row.createDate }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" fixed="right" align="center" min-width="180" class-name="small-padding fixed-width">
        <template slot-scope="{ row }">
          <el-button v-permission="['dataextraction:DataExtractionGroup:update']" type="text" size="small" icon="el-icon-edit" @click="handleUpdate(row)">
            {{ $t('table.edit') }}
          </el-button>
          <el-button
            v-permission="['dataextraction:DataExtractionGroup:delete']"
            type="text"
            size="small"
            icon="el-icon-delete"
            class="delete-text-btn"
            @click="handleDelete(row)"
          >
            {{ $t('table.delete') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" :page-sizes="pageArray" @pagination="getList" />

    <data-extraction-group-form ref="form" @refreshList="getList" />
  </div>
</template>

<script>
import {
  deleteDataExtractionGroup,
  fetchDataExtractionGroupList
} from '@/api/dataextractiongroup/dataExtractionGroup'
import waves from '@/directive/waves' // waves directive
import permission from '@/directive/permission/permission'
import dataExtractionGroupForm from './dataExtractionGroupForm'
import Pagination from '@/components/Pagination'

export default {
  name: 'DataExtractionGroupList',
  components: { dataExtractionGroupForm, Pagination },
  directives: { waves, permission },
  data() {
    return {
      size: '',
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      pageArray: this.$store.getters.pageArray,
      listQuery: {
        appName: undefined,
        page: 1,
        limit: this.$store.getters.defaultPageSize
      }
    }
  },
  created() {
    this.getList()
    window.addEventListener('resize', this.sizeFun)
  },
  mounted() {
    this.sizeFun()
  },
  methods: {
    sizeFun() {
      this.size = document.documentElement.clientHeight - 450
    },
    getList() {
      this.listLoading = true
      fetchDataExtractionGroupList(this.listQuery).then((response) => {
        this.list = response.data.data
        this.total = response.data.total
        this.listLoading = false
      })
    },
    handleCreate() {
      this.$refs.form.handleCreate()
    },
    handleUpdate(row) {
      this.$refs.form.handleUpdate(row.id)
    },
    handleDelete(row) {
      this.$confirm('删除任务会级联删除任务日志，是否确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteDataExtractionGroup(row.id).then((response) => {
          if (response.data.code === 0) {
            this.getList()
            this.$message.success(response.data.msg)
          } else {
            this.$message.error(response.data.msg)
          }
        })
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    //重置
    handleRest() {
      this.listQuery = {
        page: 1,
        limit: this.$store.getters.defaultPageSize
      }
      this.getList()
    }
  }
}
</script>
<style lang="scss" scoped>
::v-deep(::-webkit-scrollbar) {
  display: block !important;
}

.span {
  color: #606266;
  font-weight: 700;
  font-size: 14px;
}
</style>
